/**
 * html5 localstorage
 * html5本地存储数据
 * 使用localstorage存储，保存类型为字符串，格式为键值对（key-value)
 */

Newtouch.StorageUtil={
		/**
		 * 对localstorage赋值
		 * 用于添加新值和更新旧值
		 * 参数：
		 *     key:存储的键值名称，string类型
		 *     value:存储的数据，string类型
		 */
		setItem:function(key,value){
	            if(Newtouch.StorageUtil._support){
	            	  localstorage.setItem(key,value);
	            }
	
		},
		/**
		 * 获取localstorage本地存储的值
		 */
		getItem:function(key){
			 if(Newtouch.StorageUtil._support){
           	  localstorage.getItem(key);
           }
			
		},
		/**
		 * 删除localstorage对应key的值
		 */
		removeItem:function(key){
			 if(Newtouch.StorageUtil._support){
           	  localstorage.removeItem(key);
           }
			
		},
		/**
		 * 清空localstorage所有的内容
		 */
		clean:function(){
			 if(Newtouch.StorageUtil._support){
           	  localstorage.clear();
           }
			
		},
		/**
		 * 判断浏览器是否支持localstorage
		 */
		_support:function(){
			if(!window.localstorage||localstorage){
				console.log("当前浏览器不支持localstorage!");
			    return false;
			}
			else
				return true;
		}
	
	
	
}


//屏蔽输入法回车提交事件(防止页面自动刷新重载)
document.onkeydown = function(e){
    var ev = document.all ? window.event : e;
    if(ev.keyCode==13) {               
       return false;
    }
};

//页面dom缓存生命周期管理	
//data-dom-cache="true"
(function($, undefined) {
    $.fn.removePageAfterHistoryBack = function(options) {
        $(this).bind(
            "pagehide",
            function() {
                var forword = $.mobile.urlHistory.getNext();
                if (forword) {
                    var dataUrl = forword.pageUrl;
                    var forwordPage=$.mobile.pageContainer
                            .children(":jqmData(url='" + dataUrl + "')");
                    if(forwordPage){
                        forwordPage.remove();
                    }
                }
                $.mobile.urlHistory.clearForward();
                console.log(dataUrl+"--->remove")
            });
    };
})(jQuery);

//jqm url参数传递
$(document).bind('pagebeforechange',function(e,data){  
    if (typeof data.toPage !== "string"){  
        return;  
    }  
    var paramUrl = $.mobile.path.parseUrl(data.toPage);  
    var params = getUrlParam(paramUrl.search); 
});  
  
function getUrlParam(string) {  
    var obj = {};  
    if (string.indexOf("?") != -1) {  
        var string = string.substr(string.indexOf("?") + 1);  
        var strs = string.split("&");  
        for(var i = 0; i < strs.length; i ++) {  
            var tempArr = strs[i].split("=");  
            obj[tempArr[0]] = unescape(tempArr[1]);  
        }  
    }  
    return obj;  
}  
